import React from 'react';
import { Form, DatePicker, Input } from 'antd';
import { SearchInput } from '@/components/UserForm';
import AdvancedSearch from '@/components/AdvancedSearch';
// import { getTypeList } from '@/services/dictionary';
import { getServicePersonlist, getemployeebyRole } from '@/services/attendance/overtime';
import { getGradeList } from '@/services/organization';
import { withRouter } from 'umi';
import CompanyType from './CompanyType';

// import { findCountry } from './utils';
import styles from '../../RecruitMange.less';

const { RangePicker } = DatePicker;
/**
 * 头部搜索表单
 * */
const SearchForm = ({ form, user, isUser, isHR, reset, submit, collapsed }) => {
    const { getFieldDecorator } = form;

    // const handelCompanyType = (V = {}) => {
    //     const { leixingzhiwei } = form.getFieldsValue();
    //     if (V.companyTypeRemak) {
    //         form.setFieldsValue({
    //             leixingzhiwei: {
    //                 postType: null,
    //                 postRank: null,
    //                 postTypeRemark: V.companyTypeRemak
    //             }
    //         });
    //     } else {
    //         form.setFieldsValue({
    //             leixingzhiwei: {
    //                 ...leixingzhiwei
    //             }
    //         });
    //     }
    // };
    // const { postTypeRemark = 'GroupRecruitPostType' } = findCountry(user.companyId);
    const handelRest = () => {
        form.resetFields();
        reset();
    };
    return (
        <AdvancedSearch
            form={form}
            onSubmit={submit}
            onReset={handelRest}
            expand={!collapsed}
            colConfig={{
                xxl: 8,
                xl: 12,
                lg: 24,
                md: 24,
                sm: 24,
                xs: 24
            }}
        >
            <Form.Item label="职位">
                {getFieldDecorator('recruitPost', {
                    initialValue: null,
                    rules: []
                })(<Input placeholder="请输入关键字搜索职位" style={{ width: '100%' }} allowClear />)}
            </Form.Item>
            <Form.Item label="公司部门" className={styles.temp}>
                {getFieldDecorator('companyDepart', {
                    initialValue: {
                        companyId: user.companyId,
                        // eslint-disable-next-line no-nested-ternary
                        departmentId: null
                    },
                    rules: []
                })(<CompanyType permissionCode={null} />)}
            </Form.Item>
            {/* <Form.Item label="类型-职级">
                {getFieldDecorator('leixingzhiwei', {
                    initialValue: {
                        postTypeRemark: '',
                        postType: '',
                        postRank: ''
                    },
                    rules: []
                })(
                    <SimpleCascade
                        getData={params =>
                            getTypeList(params).then(res => {
                                if (res && res.code === 10000 && res.data) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                    />
                )}
            </Form.Item> */}
            <Form.Item label="申请时间">
                {getFieldDecorator('shenqing', {
                    initialValue: [],
                    rules: []
                })(<RangePicker />)}
            </Form.Item>
            {!isUser && (
                <Form.Item label="业务负责人">
                    {getFieldDecorator('servicePersonId', {
                        initialValue: undefined,
                        rules: []
                    })(
                        <SearchInput
                            params={{
                                companyId: user.companyId
                            }}
                            requireParam={['companyId']}
                            getData={params =>
                                getServicePersonlist(params).then(res => {
                                    if (res && res.code === 10000) {
                                        return res.data || [];
                                    }
                                    return [];
                                })
                            }
                            selectProps={{
                                placeholder: '请输入姓名',
                                allowClear: true,
                                style: { width: '200px' }
                            }}
                            fieldsName={{
                                value: 'id',
                                title: 'employeeName',
                                extraParams: 'userName'
                            }}
                        />
                    )}
                </Form.Item>
            )}
            {!isHR && (
                <Form.Item label="招聘负责人">
                    {getFieldDecorator('leaderIds', {
                        initialValue: [],
                        rules: []
                    })(
                        <SearchInput
                            params={{
                                companyId: user.companyId,
                                roleName: '招聘负责人' // TODO： 后面服务端会给字典
                            }}
                            getData={params =>
                                getemployeebyRole(params).then(res => {
                                    if (res && res.code === 10000) {
                                        return res.data || [];
                                    }
                                    return [];
                                })
                            }
                            fieldsName={{
                                value: 'id',
                                title: 'employeeName',
                                extraParams: 'employeeName',
                                getemployeebyRole: true
                            }}
                            selectProps={{
                                placeholder: '请输入姓名',
                                mode: 'multiple',
                                maxTagCount: 3,
                                style: { width: '200px' }
                            }}
                        />
                    )}
                </Form.Item>
            )}
            <Form.Item label="职级">
                {getFieldDecorator('postGradeCodeList', {
                    initialValue: [],
                    rules: []
                })(
                    <SearchInput
                        params={{
                            companyId: user.companyId
                        }}
                        getData={params =>
                            getGradeList(params).then(res => {
                                if (res && res.code === 10000) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        fieldsName={{
                            value: 'gradeCode',
                            title: 'gradeCode'
                        }}
                        selectProps={{
                            mode: 'multiple',
                            maxTagCount: 3,
                            placeholder: '请选择职级'
                        }}
                    />
                )}
            </Form.Item>
        </AdvancedSearch>
    );
};

export default withRouter(SearchForm);
